package fi.foyt.cs.actions;

import org.apache.commons.lang.math.NumberUtils;
import org.apache.commons.lang3.StringUtils;
import org.restlet.resource.ServerResource;

import fi.foyt.cs.persistence.domainmodel.system.ExternalLinkVerificationCode;

public class ActionResource extends ServerResource {
  
  protected String getExtraParameter(ExternalLinkVerificationCode externalLinkVerificationCode, String name) {
    if (!StringUtils.isBlank(externalLinkVerificationCode.getExtra())) {
      String[] parameters = externalLinkVerificationCode.getExtra().split(",");
      for (String parameter : parameters) {
        String[] splitted = parameter.split("=");
        if (name.equals(splitted[0]))
          return splitted[1];
      }
    }
    
    return null;
  }
 
  protected Long getExtraParameterLong(ExternalLinkVerificationCode externalLinkVerificationCode, String name) {
    return NumberUtils.createLong(getExtraParameter(externalLinkVerificationCode, name));
  }
  
}
